<template>
	<view class="page-container">
		<!-- 顶部导航栏 -->
		<view class="header">
			<x-status-bar></x-status-bar>
			<view class="flex-center-between header-navbar">
				<x-back-btn></x-back-btn>
				<view class="u-f-40 common-title">{{ lang_goods.collageList }}</view>
				<view></view>
			</view>

			<!-- 分割线 -->
			<u-gap height="1" bgColor="rgba(0, 0, 0, 0.07)"></u-gap>
		</view>

		<!-- 列表 -->
		<view class="u-p-t-6">
			<mescroll-body height="calc(100vh - 304rpx - var(--status-bar-height))" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<view style="padding: 0 30rpx;">
					<view v-for="(item, index) in dataList" :key="index" class="u-p-t-12 flex-center">
						<commodity-card :item="item"></commodity-card>
					</view>
				</view>
			</mescroll-body>
			<!-- 留空 -->
			<view style="height: 200rpx"></view>
		</view>
	</view>
</template>

<script>
	import { goodsPage } from '@/api/user/goods.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				goodsId: '',
				dataList: []
			}
		},
		onLoad({
			goodsId
		}) {
			this.goodsId = goodsId
		},
		onShow() {
			this.downCallback()
		},
		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let node = this.$refs['mescrollRef']
				goodsPage({
					pageNumber: page.num,
					pageSize: page.size,
					goodsType: 4
				}).then(res => {
					node && node.mescroll.endSuccess(res.list.length);
					if (page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(res.list); //追加新数据
				}).catch(() => {
					node && node.mescroll.endErr();
				})
			},
			downCallback() {
				let node = this.$refs['mescrollRef']
				node && node.mescroll.resetUpScroll()
			},
		}
	}
</script>

<style scoped lang="scss">

</style>
